package com.paradogs.framework.core.netty.server;

import com.baidu.bjf.remoting.protobuf.annotation.ProtobufClass;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author: yumi
 * @date: 2023/7/27  10:02
 * @Description: TODO
 */
@Data
@Component
@Scope("prototype")
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
@ProtobufClass
@ConfigurationProperties("paradogs.server")
public class ServerProperties {

    /**
     * 端口
     */
    @Value("${paradogs.server.port:80}")
    private int port;

    /**
     * 服务类型，相同服务类型相同
     * @value 用于未配置时报错
     */
    @Value("${paradogs.server.type}")
    private String type;

    /**
     * 服务名称
     */
    private String key;

    /**
     * 是否为 master，用于判断 master 不连接自身
     */
    private boolean master = false;

    public String getKey() {
        if (StringUtils.isNotBlank(this.key)) {
            return this.key;
        }
        return this.key = UUID.randomUUID().toString().replace("-", "");
    }

}
